package com.yun.zf.common.admin.model.house;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.yun.zf.common.utils.StringUtils;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.math.BigDecimal;
import java.util.Date;

@Data
public class HouseListMo {
    @ApiModelProperty(value = "省级区划代码")
    private Long provinceCode;

    @ApiModelProperty(value = "城市编码")
    private Long cityCode;
    @ApiModelProperty(value = "标题")
    private String title;
    @ApiModelProperty(value = "id")
    private String id;
    @ApiModelProperty(value = "区域名称")
    private String regionName;
    @ApiModelProperty(value = "街道名称")
    private String streetName;
    @ApiModelProperty(value = " 标题图")
    private String url;
    @ApiModelProperty(value = "小区ID")
    private String communityId;
    @ApiModelProperty(value = "楼盘名称")
    private String community;
    @ApiModelProperty(value = "户型")
    private int bedrooms;
    @ApiModelProperty(value = "客厅")
    private Integer livingRoom;
    @ApiModelProperty(value = "卫生间")
    private Integer toilet;
    @ApiModelProperty(value = "面积")
    private BigDecimal area;
    @ApiModelProperty(value = "价格")
    private BigDecimal hopedPrice;
    @ApiModelProperty(value = "价格单位")
    private String priceUnit;

    @ApiModelProperty(value = "二手房均价")
    private String averagePrice;

    @ApiModelProperty(value = "楼层")
    private String floorTag;
    private String floorTagAZH;
    @ApiModelProperty(value = "总楼层")
    private Integer totalFloor;
    @ApiModelProperty(value = "朝向")
    private String direction;
    private String directionZH;
    @ApiModelProperty(value = "维护人")
    private String recordName;
    @JsonFormat(pattern = "yyyy-MM-dd")
    @ApiModelProperty(value = "修改时间")
    private Date modifiedTime;
    @ApiModelProperty(value = "是否推荐")
    private String isRecommend;
    @ApiModelProperty(value = "推荐理由")
    private String recommendReason;
    @ApiModelProperty(value = "标签")
    private String tags;
    @ApiModelProperty(value = "标签名称")
    private String tagsName;

    public String getDirectionZH() {
        JSONArray ja = JSON.parseArray(direction);
        StringBuffer sb = new StringBuffer();
        String name = "";
        if (ja != null && ja.size() > 0) {
            for (int i = 0; i < ja.size(); i++) {
                String s = ja.getString(i);
                switch (s) {
                    case "N":
                        name = "北";
                        break;
                    case "S":
                        name = "南";
                        break;
                    case "E":
                        name = "东";
                        break;
                    case "W":
                        name = "西";
                        break;
                }
                if (StringUtils.isNotBlank(name)) {
                    sb.append(name);
                    if (i != ja.size() - 1) {
                        sb.append(",");
                    }
                }
            }
            return  JSON.toJSONString(sb.toString().split(","));
        }

        return "";
    }

    public String getFloorTagAZH() {
        String name="";
        if (StringUtils.isBlank(floorTag)){
            return  name;
        }
        switch (floorTag){
            case "bottom":
                name = "底层";
                break;
            case "low":
                name = "低楼层";
                break;
            case "middle":
                name = "中楼层";
                break;
            case "high":
                name = "高楼层";
                break;
            case "top":
                name = "顶层";
                break;
            default:
                name="";
        }
        return name;
    }

    public String getTagsName() {
        JSONArray ja = JSON.parseArray(tags);
        StringBuffer sb = new StringBuffer();
        String name = "";
        if (ja != null && ja.size() > 0) {
            for (int i = 0; i < ja.size(); i++) {
                String s = ja.getString(i);
                switch (s) {
                    case "JDT":
                        name = "近地铁";
                        break;
                    case "LBRZ":
                        name = "拎包入住";
                        break;
                    case "JZX":
                        name = "精装修";
                        break;
                    case "BKHF":
                        name = "必看好房";
                        break;
                    case "MW":
                        name = "满五年";
                        break;
                    case "ML":
                        name = "满两年";
                        break;
                    case "YYFY":
                        name = "押一付一";
                        break;
                    default:
                        name="";
                }
                if (StringUtils.isNotBlank(name)) {
                    sb.append(name);
                    if (i != ja.size() - 1) {
                        sb.append(",");
                    }
                }
            }
            return  JSON.toJSONString(sb.toString().split(","));
        }

        return "";
    }

    public static void main(String[] args) {
        String s = "1,2,3";
        System.out.println(JSON.toJSONString(s.split(",")));
    }
}
